<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>权限设置</title>
    <meta name="keywords" content="权限设置">
    <meta name="description" content="权限设置">

    <link rel="shortcut icon" href="favicon.ico">

    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/css/bootstrap.min.css'"
          href="../asset/js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/fonts/iconfont.css'"
          href="../asset/css/fonts/iconfont.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/ui.jqgridffe4.css'"
          href="../asset/js/plugins/jqgrid/ui.jqgridffe4.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/animate.min.css'" href="../asset/css/animate.min.css"
          rel="stylesheet">

    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/font-awesome.min.css'" rel="stylesheet"
          href="../asset/css/font-awesome.min.css" />
    <link rel="stylesheet" th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/css/zTreeStyle/zTreeStyle.css'"
          href="../asset/js/ztree/css/zTreeStyle/zTreeStyle.css"/>
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/style.min862f.css'"
          href="../asset/css/style.min862f.css" rel="stylesheet">



</head>

<body class="gray-bg">


<div class="wrapper wrapper-content  animated fadeInRight">


    <div class="ibox float-e-margins">
        <div class="ibox-title">
            权限设置
        </div>
        <div class="row ibox-content">
            <form class="form-horizontal m-t" id="formSubmit">

                <div class="form-group">
                    <div class="col-sm-12">
                        <input id="roleId" name="roleId" type="hidden">
                        <ul id="tree" class="ztree"></ul>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-8 col-sm-offset-3">
                        <button class="btn btn-primary" id="btnSubmit" type="submit">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

</div>

<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/jquery/jQuery-2.2.0.min.js'"
        src="../asset/js/jquery/jQuery-2.2.0.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/js/bootstrap.min.js'"
        src="../asset/js/bootstrap/js/bootstrap.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/content.min.js'"
        src="../asset/js/content.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/validate/jquery.validate.min.js'"
        src="../asset/js/plugins/validate/jquery.validate.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/layer/layer.js'"
        src="../asset/js/plugins/layer/layer.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/validate/messages_zh.min.js'"
        src="../asset/js/plugins/validate/messages_zh.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/js/jquery.ztree.core.min.js'"
        src="../asset/js/ztree/js/jquery.ztree.core.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/ztree/js/jquery.ztree.excheck.min.js'"
        src="../asset/js/ztree/js/jquery.ztree.excheck.min.js"></script>

<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/comm.js'" src="../asset/js/comm.js"></script>
<script type="text/javascript">
    var zTreeObj;
    function initView() {
        var request=app.getRequest();
        var roleId=request["id"];
        $("#roleId").val(roleId);
        initmenu(roleId);
//        getDetail();
        //初始化左机构
        //获取资源类别
//        getType();
    }
    //渲染界面编辑数据
    function initFormView(data) {
        app.initFormView("#formSubmit", data);
        $("#officeName").text(data.officeName);
    }

    //获取数据
    function getDetail() {
        var id = app.getRequest()["id"];
        if (id && id.length > 0) {//编辑
            app.post("/admin/role/detail", {id: id}, function (data) {
                initFormView(data);
            });
        }

    }


    function initmenu(roleId) {
        //初始化树结构
        var setting = {
            async: {
                enable: true,
                url: "/admin/menu/userMenusTree?roleId="+roleId,
                autoParam: ["id"]
            },
            check: {
                enable: true
            },
            view: {
                selectedMulti: true,
                showLine: true
            },
            callback: {
                onCheck: function (event, treeId, treeNode) {
                    $("#parentId").val(treeNode.id);
                    var ids="0"+getMenusIdsStr(treeNode);
                    $("#parentIds").val(treeNode.id);
                    console.log(ids);
                },
                beforeAsync: function () {
                    app.loding();
                },
                onAsyncError:function () {
                    app.close();
                },
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                    var treeObj = $.fn.zTree.getZTreeObj(treeId);
                    app.close();
                    treeObj.expandAll(true);
                }
            }
        };
        zTreeObj = $.fn.zTree.init($("#tree"), setting);
    }

    $().ready(function () {
        //渲染界面
        initView();
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        })
        var e = "<i class='fa fa-times-circle'></i> ";
        var formValidate = {
            rules: {
            },
            messages: {
            },
            debug: true,
            submitHandler: function (form) {
                var parm =app.getFormJson("#formSubmit");

               var nodes=  zTreeObj.getCheckedNodes(true);
               if(!nodes||nodes.length<1){
                   app.tip("请选择资源");
                   return;
               }
               var ids=[];
               $.each(nodes,function (index,val) {
                   console.log("val:"+val+"======index:"+index);
                   ids.push(val.id);
               })
               console.log(nodes);
               var parm=$.extend(parm,{menusIds:JSON.stringify(ids)});
                console.log(parm);
                app.post("/admin/role/power", parm, function (data) {
                    app.closeParent();
                    var grid = window.parent.location.reload(); //刷新父页面
                });
            }
        };
        $("#formSubmit").validate(formValidate);
    });
</script>
</body>
</html>
